//登录认证模块
let loginUrl = '/auth/oauth/token'
let refreshLoginUrl = '/auth/oauth/token'

// 获得位置
let getLocationUrl = 'http://api.map.baidu.com/reverse_geocoding/v3/?ak=DDgMRRvbCrE9I4VeqWLpEzsee1vmVenE&output=json&coordtype=wgs84ll&location=39.9,116.4'

// 获得dept树
let getDeptTreeUrl = '/admin/dept/tree'
/*
	用户模块
	:author cy
*/

// 获取用户基本信息
let getUserInfoUrl = '/act/userInfo/get'
// 获取用户的部门信息
let getDeptListUrl = '/act/userInfo/getDeptList'
// 获取用户的详细管理权限信息
let getUserPermissionUrl = '/act/userInfo/getRoleList'


/*
	打卡相关
	:author cy
*/ 
let submitClockUrl = '/act/clock/save'
// 获取近期打卡内容
let getRecentPartInfoUrl = '/act/clock/getRecentPartInfo'
// 获取历史打卡记录（分页）
let getPageRecordsUrl = '/act/clock/getPageRecords' 
// 获取当日有无打卡
let isClockedUrl = '/act/clock/isClocked'
// 获取部门打卡简略信息
let getDeptSimpleInfoUrl = '/act/clock/getDeptSimpleInfo'
// 获取部门打卡详细信息
let getDeptAllInfoUrl = '/act/clock/getDeptAllInfo'
// 获取部门未打卡名单
let getDeptUnClockedInfoUrl = '/act/clock/getDeptUnClockedInfo'


/*
	请假相关
	author: cy
*/
// 获取全部流程
let getAllDeploymentUrl = '/act/deploy/get/all/deployment'
// 提交请假表单
let submitLeaveUrl = '/act/userLeave/save'
// 获取所有请假信息
let getAllLeaveUrl = '/act/userLeave/getAll'
// 撤销请假申请
let revokeLeaveUrl = '/act/userLeave/revoke'
// 拒绝请假申请
let rejectLeaveUrl = '/act/task/leave/refuseTask'
// 同意审批
let acceptLeaveUrl = '/act/task/leave/handleTask'
// 删除审批
let deleteLeaveByIdUrl = '/act/userLeave/revoke/'

// 获取待审批的申请
let getCandidateTaskUrl = '/act/task/leave/getCandidateTask'
// 获取已同意的请假申请
let getPassedLeavesUrl = '/act/task/leave/getPassedLeaves'
// 获取已拒绝的申请申请
let getRefusedLeavesUrl = '/act/task/leave/getRefusedLeaves'


/*
	三进相关
	author: cy
*/
// 提交三进打卡
let submitTrienterUrl = '/act/enter/save'
// 查看自己的打卡记录
let getTrienterHistoryUrl = '/act/enter/records'
// 查看自己管理的人员的三进打卡情况
let getSubordinaryTrienterHistoryUrl = '/act/enter/records/all'


//工作流模块
// let getLeaveBillPageUrl = "/act/leave-bill/self/page"
// let getLeaveTypeUrl = '/admin/dict/type/leave_type'


const install = (Vue, vm) => {
	
	
	let getLocation = () => vm.$u.get(getLocationUrl)
	let loginByUsername = (params = {}) => vm.$u.post(loginUrl,params)
	let refreshLogin = () => {
		let lifeData = uni.getStorageSync('lifeData')
		// console.log(lifeData)
		
		let params = {
			'grant_type': 'refresh_token',
			'scope': 'server',
			'refresh_token': lifeData.refresh_token
		}
		return vm.$u.post(refreshLoginUrl, params)
	}
	
	let getUserInfo = (userId) => vm.$u.get(getUserInfoUrl+"?userId=" + userId)
	let getRecentPartInfo = () => vm.$u.get(getRecentPartInfoUrl)
	let submitClock = (params = {} ) => vm.$u.put(submitClockUrl,params)
	let getPageRecords = (params = {}) => vm.$u.post(getPageRecordsUrl,params)
	let isClocked = () => vm.$u.get(isClockedUrl)
	let getUserPermission = (userId) => vm.$u.get(getUserPermissionUrl)
	
	
	let getDeptList = () => vm.$u.get(getDeptListUrl)
	let getDeptSimpleInfo = (params = {}) => {
		let url = getDeptSimpleInfoUrl
			+"?date="+params['date'].trim()
			+"&deptId="+params['deptId']
			+"&userId="+(params['userId']===undefined?0:params['userId'])
			
		return vm.$u.get(url)
	}
	let getDeptAllInfo = (params = {}) => {
		let url = getDeptAllInfoUrl
			+"?date="+params['date'].trim()
			+"&deptId="+(params['deptId']===undefined?0:params['deptId'])
			+"&userId="+(params['userId']===undefined?0:params['userId'])
			
		console.log('get url:', url)
		return vm.$u.get(url)
	}
	
	let getDeptUnClockedInfo = (params = {}) => {
		let url = getDeptUnClockedInfoUrl
			+"?date="+params['date'].trim()
			+"&deptId="+(params['deptId']===undefined?0:params['deptId'])

		console.log('get getDeptUnClockedInfo:', url)
		return vm.$u.get(url)
	}
	
	let getDeptTree = () => vm.$u.get(getDeptTreeUrl)
	
	
	/* 请假相关 */
	let getAllDeployment = () => vm.$u.get(getAllDeploymentUrl)
	let submitLeave = (param) => vm.$u.put(submitLeaveUrl, param)
	let getAllLeave = () => vm.$u.get(getAllLeaveUrl)
	let revokeLeave = (param) => vm.$u.post(revokeLeaveUrl, param)
	let rejectLeave = (param) => vm.$u.post(rejectLeaveUrl, param)
	let acceptLeave = (param) => vm.$u.post(acceptLeaveUrl, param)
	
	let getCandidateTask = (param) => vm.$u.get(getCandidateTaskUrl, param)
	let getPassedLeaves = () => vm.$u.get(getPassedLeavesUrl)
	let getRefusedLeaves = () => vm.$u.get(getRefusedLeavesUrl)
	let deleteLeaveById = (param) => vm.$u.delete(deleteLeaveByIdUrl+param.taskId)
	
	
	/* 三进相关 */
	let submitTrienter = (param) => vm.$u.put(submitTrienterUrl, param)
	let getTrienterHistory = (param) => {
		let url = getTrienterHistoryUrl + '?date=' + param.date
		return vm.$u.get(url)
	}
	let getSubordinaryTrienterHistory = (param) => {
		let url = getSubordinaryTrienterHistoryUrl + '?date=' + param.date
		return vm.$u.get(url)
	}
	// let getLeaveBillPage = (params = {}) => vm.$u.get(getLeaveBillPageUrl,params)
	// let getLeaveType = () => vm.$u.get(getLeaveTypeUrl)
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		loginByUsername,
		getUserInfo,
		getRecentPartInfo,
		submitClock,
		getPageRecords,
		isClocked,
		getDeptList,
		getDeptSimpleInfo,
		getDeptAllInfo,
		getDeptTree,
		getDeptUnClockedInfo,
		getAllDeployment,
		submitLeave,
		getUserPermission,
		getAllLeave,
		revokeLeave,
		getCandidateTask,
		getPassedLeaves,
		getRefusedLeaves,
		rejectLeave,
		acceptLeave,
		submitTrienter,
		getTrienterHistory,
		getSubordinaryTrienterHistory,
		getLocation,
		deleteLeaveById,
		refreshLogin
		// getLeaveBillPage,
		// getLeaveType
	};
}

export default {
	install
}